﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <LinearGradientBrush x:Key="KeyListViewItem_BackgroundOver" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#F4F7FC" Offset="0"/>
        <GradientStop Color="#E3EEFC" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="KeyListViewItem_BackgroundSelected" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#E8F1FE" Offset="0"/>
        <GradientStop Color="#CDE3FE" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="KeyListViewItem_BackgroundSelectedOver" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#D9EAFC" Offset="0"/>
        <GradientStop Color="#BED9FC" Offset="1"/>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="KeyListViewGroups_Background" EndPoint="0,1" StartPoint="0,0">
        <GradientStop Color="#FFE7A4" Offset="0"/>
        <GradientStop Color="#FFE8A6" Offset="0.5"/>
        <GradientStop Color="#FDD04F" Offset="1"/>
    </LinearGradientBrush>

    <DataTemplate x:Key="KeyItemPhotoDataTemplate">
        <Border BorderBrush="Gray" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 0 8 0">
            <Image Width="38" Stretch="Uniform">
                <Image.Style>
                    <Style TargetType="Image">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=Photos, Converter={StaticResource NullOrEmptyConverter}}" Value="True">
                                <Setter Property="Source" Value="/WgpgCore;component/Images/No_Image_Available_Small.gif" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=Photos, Converter={StaticResource NullOrEmptyConverter}}" Value="False">
                                <Setter Property="Source" Value="{Binding Path=Photos[0].Image, Converter={StaticResource ImageToBitmapConverter}, IsAsync=True}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Image.Style>
            </Image>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="KeyItemDataTemplate">
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <ContentControl Content="{Binding}" ContentTemplate="{StaticResource KeyItemPhotoDataTemplate}" Grid.RowSpan="3" Grid.Column="0" Grid.Row="0" />

            <TextBlock Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" Text="{Binding Path=UserInfos[0].FullInfo}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>
            <TextBlock Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="Gray">Key Id: <TextBlock Text="{Binding Path=Id}"/></TextBlock>
            <TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Top" Foreground="Gray" Text="{Binding Path=OwnerTrust, Converter={StaticResource OwnerTrustToStringConverter}}"/>
        </Grid>
    </DataTemplate>
    
    <Style x:Key="KeyListViewItem" TargetType="{x:Type ListViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Padding" Value="1,0,0,0"/>
        <Setter Property="Margin" Value="0"/>
        <Setter Property="Tag" Value="{Binding}"/>
        <Setter Property="FocusVisualStyle">
            <Setter.Value>
                <Style />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <Border CornerRadius="4" Name="Bd" Padding="8" BorderBrush="Transparent" BorderThickness="1">
                        <ContentPresenter ContentTemplate="{StaticResource KeyItemDataTemplate}" HorizontalAlignment="Stretch"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="BorderBrush" TargetName="Bd" Value="#82ABDC"/>
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource KeyListViewItem_BackgroundSelected}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="Bd" Value="#B4D3FA"/>
                            <Setter Property="Background" TargetName="Bd" Value="{StaticResource KeyListViewItem_BackgroundOver}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True"/>
                                <Condition Property="IsMouseOver" Value="True"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter Property="BorderBrush" TargetName="Bd" Value="#7CA1CE"/>
                                <Setter Property="Background" TargetName="Bd" Value="{StaticResource KeyListViewItem_BackgroundSelectedOver}"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="KeyListViewGroups" TargetType="{x:Type GroupItem}">
        <Setter Property="Margin" Value="0,0,0,5"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <StackPanel>
                        <TextBlock Padding="10,6,10,6" FontWeight="Bold" Foreground="Black" Background="{StaticResource KeyListViewGroups_Background}">
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=Name}" Value="Pair">
                                            <Setter Property="Text" Value="My keys"/>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Path=Name}" Value="Public">
                                            <Setter Property="Text" Value="Keys of my contacts"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                        <ItemsPresenter />
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
